<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" id="vp" content="width=device-width, initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
		<title>我的学校</title>
		
		<link rel="stylesheet" type="text/css" href="../../../css/style.css">
		<link href="../../../css/mui.min.css" rel="stylesheet" type="text/css" />
	
		<style>
			#shop .as{
				margin-top: 41px;
			}
			.schoolBanner img{
				width: 100%;
			}
			.IndOneM span{
				margin-right: 10px;
			}
			.myschoolContent{
		      padding:15px 15px 10px 15px;
		      background: #fff;
			}
			.myschoolContent .title{
				padding-bottom: 10px;
			}
			.myschoolContent .IndOneI img{
				min-height: 80px;
			}
			.guanzhu{
				border: solid 1px #d88343;
				color: #df8f36;
				padding: 0 2px;
				font-size: 12px;
			}
			.jianjie{
				display: -webkit-box;
				-webkit-box-orient: vertical;
				-webkit-line-clamp: 2;
				overflow: hidden;
				font-size: 12px;
				line-height: 15px;
				padding-top: 5px;
			}
			.IndOneM{
				width: 100%;
				padding-top: 5px;
				font-size: 12px;
			}
			.IndOneN{
				
				padding-bottom: 10px;
				margin-bottom: 10px;
			}
			.IndOneBtitle{
				white-space:nowrap;
				overflow:hidden;
				text-overflow:ellipsis;
				width: 3rem;
			}
			#myschools .list-ip-img2{
				width: 1.8rem;
				height: 1.7rem;
			}
			#myschools .list-info-picBackground{ 
				 background-repeat: no-repeat; background-size:cover; background-position:50%;
			}
		</style>
	</head>
	<body>
		<div id="myschools">
			<div id="pullrefresh" class="mui-content mui-scroll-wrapper list-frame" style="background: #fff;">
			<div class="mui-scroll">
			<div class="myschoolContent" id="recommend-list">
				<!--<div class="title">我的学校({{itemcount}})</div>  -->
				<div class="">
					<div class="IndOneN IndO1" style=" display:block;" >
						<a href="JavaScript:;" class="IndOneA" v-for="item in myitems"  @tap="schooldetail(item)"> 
			            	<div class="IndOneI fl">
			            		<div :style="{backgroundImage:'url(' + item.institution_avatar + ')'}" class="list-ip-img2 list-info-picBackground"></div>
			            		<!--img :src="item.institution_avatar" width="100%" /-->
			            	</div>
			                <div class="IndOneP fr">
			                	<div class="IndOneB">
			                		<span class='IndOneBtitle fl'>{{item.institution_name}}</span>
			                	
			                	</div>
			                	<div class="clear"></div>
			                	<div class="jianjie">
			                		{{item.institution_introduction}}
			                	</div>
			                    <div class="IndOneC">
			                        <div class="IndOneM">
			                        	<!--span>{{item.distance}}</span-->
			                        	<span class="fr">关注{{item.code_number}}</span>
			                        	<span class="IndOeye">{{item.views}}</span>
			                        </div>
			                        	<div class="clear"></div>
			                    </div>
			                </div><div class="clear"></div> 
			           </a>          
			        	<a href="JavaScript:;" class="IndOneA" v-for="(item,key,index) in items" @tap="schooldetail(item)"> 
			            	<div class="IndOneI fl"><div :style="{backgroundImage:'url(' + item.institution_avatar + ')'}" class="list-ip-img2 list-info-picBackground"></div></div>
			                <div class="IndOneP fr">
			                	<div class="IndOneB">
			                		<span class='IndOneBtitle fl'>{{item.institution_name}}</span>
			                		<div class="guanzhu fr" @tap='guanzhuchange(item,event)' aria-hidden="true">取消关注</div> 
			                	</div> 
			                	<div class="clear"></div>
			                	<div class="jianjie">
			                		{{item.institution_introduction}} 
			                	</div>
			                    <div class="IndOneC">
			                        <div class="IndOneM">
			                        	<!--span>{{item.distance}}</span-->
			                        	<span class="fr">关注{{item.code_number}}</span>
			                        	<span class="IndOeye">{{item.views}}</span>
			                        </div>
			                        	<div class="clear"></div>
			                    </div>
			                </div><div class="clear"></div> 
			           </a>          
        			</div>
				</div>
			</div>
			</div>
			</div>
		</div>
		<script type="text/javascript" src="../../../js/jquery-1.8.3.min.js"></script>
		<script src="../../../js/idangerous.swiper.min.js"></script>
		<script src="../../../js/mui.min.js"></script>
		<script src="../../../js/vue.min.js"></script>
		<script src="../../../js/app.js"></script>
		<script src="../../../js/token.js"></script>
		<script>
			mui.init()
			var favoritestatus = 0;
			var pages=1;
			//mui初始化，配置下拉刷新
			mui.init({
					gestureConfig: {
						doubletap: true,
						longtap: true, //默认为false 
						click: true
					},
					pullRefresh: {
						container: '#pullrefresh',
						down: {
							callback: function() {
								pages = 1
								pulldownRefresh(pages)
							}
						},
						up: {
							contentrefresh: '正在加载...',
							callback: function() {
								pages++;
								pullupRefresh(pages)
							}
						}
					}
				});
			
			mui.plusReady(function() {
				var state = app.getState(); 
				uid = state.userid;
				memberToken = state.memberToken;
				childid = state.childid;
				
				paradata = { 
					uid: uid,
					memberToken: memberToken,
					page:1,
					child_id: childid
				}
				mui.post(Apiurl+'index/school',paradata, function(data) {
					//alert(JSON.stringify(data))
					pullrefresh.itemcount=data.count	
					if(data.my && data.my.length > 0){
						pullrefresh.myitems = data.my;
					}
					if(data.list && data.list.length > 0) {
						pullrefresh.items = data.list;  
					} 
					mui('#pullrefresh').pullRefresh().endPulldownToRefresh();  
				}, 'json');   
			 	
				//轮播图
				/*mui.post(Apiurl+'index/banner', {
					uid: uid,
					type: '4',
					memberToken: memberToken
				}, function(data) {
					myschools.banners = data;
					var bannerHtml = '';
					for(var i = 0; i < data.length; i++) { 
						bannerHtml += "<div class=\"swiper-slide\"><img src='" + data[i].banner_pic + "'></div>";
					}
					
					$(".swiper-wrapper").html(bannerHtml);

					var mySwiper = new Swiper('.swiper-container', {
						loop: true,
						pagination: '.pagination',
						paginationClickable: true,
						moveStartThreshold: 100,
						centeredSlides: true,
						autoplay: 3500,
						autoplayDisableOnInteraction: false
					})

				}, 'json');*/
			});
			var pullrefresh = new Vue({
				el: '#pullrefresh', 
				data: {
					myitems:{},
					items: [],
					itemcount:''
				},
				methods: {
					guanzhuchange: function(item,event){
						event.stopPropagation();
						paradata.code=item.code;
						var btnArray = ['否', '是'];
						mui.confirm('您是否要取消关注该学校？', '删除确认', btnArray, function(e) { 
							if(e.index == 1) {
									mui.post(Apiurl+'index/school', paradata, function(data) {
                            		if(data.status == "200") {
                            			mui.fire(plus.webview.getWebviewById("schoolsrefresh"),'refreshshcools',{
											msgid:item.institution_id
										}) 
                            			event.target.parentElement.parentElement.parentElement.remove()
                            			plus.nativeUI.toast('取消成功', {
											verticalAlign: 'middle'
										});
                            		}
                            		}, 'json')								
							}
						})	
					},
					schooldetail: function(item){
						mui.openWindow({ 
							url: '../../schools/detail.html',  
							id: 'schoolsdetail',
							extras: {
								instid: item.institution_id 
							},
							createNew:true,
							
						});
					}
					
				}
			});
			//下拉刷新
			function pulldownRefresh(pages) {
				if(window.plus && plus.networkinfo.getCurrentType() === plus.networkinfo.CONNECTION_NONE) {
					plus.nativeUI.toast('似乎已断开与互联网的连接', {
						verticalAlign: 'top'
					});
					return; 
				} 
    			paradata.page=pages;
				mui.post(Apiurl+'index/school',paradata, function(data) {
					
					pullrefresh.itemcount=data.count	
					if(data.my && data.my.length > 0){
						pullrefresh.myitems = data.my;
					}
					if(data.list && data.list.length > 0) {
						pullrefresh.items = data.list;  
					} 
					mui('#pullrefresh').pullRefresh().endPulldownToRefresh();  
				}, 'json');   
			 	
			}
			//上拉加载
			function pullupRefresh(pages) {
				paradata.page = pages//请求机构列表信息流 
				mui.post(Apiurl+'index/school', paradata, function(data) { 
					if(pages <= data.pagecount){
						if(data.list && data.list.length > 0){
							pullrefresh.items= pullrefresh.items.concat(data.list);
						}
					}
					mui('#pullrefresh').pullRefresh().endPullupToRefresh();
				}, 'json');
				
			} 
			mui('.mui-scroll-wrapper').scroll({
				deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
			});
		
		//切换孩子
		window.addEventListener('changeChild', function(event) {
			var changeChild = event.detail.changeChild;
			pages=1
			data.child_id=changeChild
			pulldownRefresh(pages)
		});
			</script>
	</body>
</html>
